version 14.2
set more off
set matsize 11000

***********************************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.XI OF WASEEM (2020) ROLE OF WITHHOLDING ...
***********************************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* ALL FIRMS */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep					if fy>1996 & fy<1999
keep                	if business_sts=="1" 
g						quarter=qofd(taxperiod)
qui						sum quarter
replace					quarter=quarter-r(min)+1
qui						sum quarter
local					qmax=r(max)
g						filed=0
forvalues				q=1/`qmax' {
replace					filed=1 if quarter==`q'
}
bys						regno quarter:g first=_n==1
bys						regno:egen nqreturn=sum(first)
keep					if nqreturn==`qmax'
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						ind=real(substr(item_cd,1,4))
run						"$project_do\Industry PCT and Description" ind
g						lnsales=log(sale_ag)
bys						indpct:egen avgfirmsize=mean(lnsales) 
drop					if indpct==1 | indpct==2 | indpct==3 | indpct==5
keep					indpct inddesc avgfirmsize input output exposale_ag regno fy lnsales period sale_ag purch_ag
g						treat=(indpct==20 | indpct==19 | indpct==12 | indpct==9)
merge 					m:1 regno using "C:\Users\Windows\Dropbox\Others\Data\Sales Tax\Master\Upto Nov 2011\master_updated_nov_2011.dta"
drop					if _merge==2
drop					_merge
local					i=1
local					j=1
qui						reg avgfirmsize treat, cluster(regno)
matrix					table[`i',`j']=_b[treat]
matrix					table[`i'+1,`j']=_se[treat]
matrix					table[`i'+4,`j']=e(N)
local					j=`j'+1
local					i=1
qui						sum initial_capital,d
g						low_init_capital=(initial_capital<r(p50))	
qui						reg low_init_capital treat, cluster(regno)
matrix					table[`i',`j']=_b[treat]
matrix					table[`i'+1,`j']=_se[treat]
matrix					table[`i'+4,`j']=e(N)
local					j=`j'+1
local					i=1
g 						inputoutputratio=ln(purch_ag/sale_ag)
qui						reg inputoutputratio treat, cluster(regno)
matrix					table[`i',`j']=_b[treat]
matrix					table[`i'+1,`j']=_se[treat]
matrix					table[`i'+4,`j']=e(N)
local					j=`j'+1
local					i=1
g 						lowinput=(purch_ag<0.05*sale_ag)
qui						reg lowinput treat, cluster(regno)
matrix					table[`i',`j']=_b[treat]
matrix					table[`i'+1,`j']=_se[treat]
matrix					table[`i'+4,`j']=e(N)
local					j=`j'+1
local					i=1
bys						regno fy:egen ansales=sum(sale_ag)
g						voluntary=0
replace 				voluntary=1 if ansales<=1000000 & fy<=1998
replace					voluntary=1 if ansales<=2500000 & fy>1998 & fy<=2003
replace					voluntary=1 if ansales<=5000000 & fy>=2004
qui						reg voluntary treat, cluster(regno)
matrix					table[`i',`j']=_b[treat]
matrix					table[`i'+1,`j']=_se[treat]
matrix					table[`i'+4,`j']=e(N)
g						after=(fy==1998)
g						treat_after=treat*after
local					j=`j'+1
local					i=3
qui						reg lnsales i.period treat after treat_after, cluster(regno)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[`i'+2,`j']=e(N)


/* FORMATTING TABLE */

svmat 			table
keep			tab*
keep			table1-table6
keep			if _n<=5
g				c11=""
replace			c11="$\mbox{\emph{Below-Average}}$" in 1
replace			c11="$\mbox{\emph{Below-Average}} \times \mbox{\emph{Post}}$" in 3
replace			c11="Observations" in 5
forvalues 		c=1/6 {
g				c`c'=string(table`c',"%9.3f")
}
foreach			r in 2 4 {
forvalues		c=1/6 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/6 {
replace			c`c'=string(table`c',"%15.0fc") in 5
}
forvalues		c=1/5 {
replace			c`c'="" in 3
replace			c`c'="" in 4
}
foreach			c in 6 {
forvalues		r=1/2 {
replace			c`c'="" in `r'
}
}
forvalues		s=1/8 {
g				s`s'="&"
}
g				l="\\"
foreach			r in 2 4 {
replace			l="\\\\" in `r'
}
browse			c11 s8 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 l

